package com.tuozixuan.sync;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class NoSynchronizedDemo {

	private int count;

	public void increment() {
		count++;
	}

	public static void main(String[] args) throws InterruptedException {

		ExecutorService executorService = Executors.newFixedThreadPool(20);
		CountDownLatch latch = new CountDownLatch(10000);
		
		NoSynchronizedDemo demo = new NoSynchronizedDemo();
		for (int i = 0; i < 10000; i++) {
			executorService.execute(() -> {
				try {
					demo.increment();
				} finally {
					latch.countDown();
				}
			});
		}

		latch.await();
		System.out.println("count:" + demo.count);
		executorService.shutdown();
	}
}
